/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2024-11-11 15:22:27
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2024-11-13 10:48:41
 * @FilePath: \project\work-tool\experi-api\middlewares\admin-auth.js
 * @Description: 登录鉴权中间件
 */
const jwt = require('../util/JWT')

module.exports = (req, res, next) => {
  const token = req.headers.authorization
  if (!token) {
    return res.status(401).json({
      message: 'Unauthorized'
    })
  }
  const decoded = jwt.verify(token, 'secret')
  req.user = decoded
  next()
}